#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
using namespace std;

class my_queue
{
public:
	void add(int newNum)
	{
		stackpush.push(newNum);
	}
	void poll()
	{
		if (stackpop.empty()) {
			PushToPop();
		}
		stackpop.pop();
	}
	int peek()
	{
		if (stackpop.empty()) {
			PushToPop();
		}
		return  stackpop.top();
	}
private:
	void PushToPop()
	{
		while (!stackpush.empty()) {
			stackpop.push(stackpush.top());
			stackpush.pop();
		}
	}
private:
	stack<int> stackpush;
	stack<int> stackpop;
};

int main()
{
	my_queue q;
	q.add(3);
	q.add(2);
	q.add(1);
	cout << q.peek();
	q.poll();
	cout << q.peek();
	q.add(4);
	q.add(5);
	q.poll();
	q.poll();
	q.poll();
	cout << q.peek();
	q.poll();
	return 0;
}
